package edu.kit.los.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.LinkedList;
import java.util.List;

import edu.kit.los.event.FacebookEventOld;


public class Test {
	
	public static void main(String[] args) throws IOException{
		List<FacebookEventOld> list = new LinkedList<FacebookEventOld>();
//		list.add(new FacebookEvent("1", "Label1", "Beschreibung1", "49.028639", "8.405914"));
//		list.add(new FacebookEvent("2", "Label2", "Beschreibung1", "49.128639", "8.405914"));
//		list.add(new FacebookEvent("3", "Label3", "Beschreibung1", "49.028639", "8.505914"));
//		list.add(new FacebookEvent("4", "Label4", "Beschreibung1", "49.028639", "8.605914"));
		
//		Gson gson = new Gson();
//
//		String str = FacebookLookup.lookup_event_String("170243523069212");
//		FacebookEvent parser = gson.fromJson(str,
//				FacebookEvent.class);
//		
//		FacebookEventOld event = new FacebookEventOld(""+parser.getId(), parser.getName(),
//				parser.getDescription(), parser.getStart_time(),
//				parser.getEnd_time(), parser.getUpdated_time(),
//				parser.getPrivacy(), parser.getOwnerName(), parser.getOwnerID(), parser.getLocation(), 
//				parser.getGeoLat(), parser.getGeoLong(), parser.getGeoID());
//		list.add(event);
//		
//		System.out.println(Converter.FacebookEventList2HTML(list));	
		
		
		URL overview_url = new URL("http://graph.facebook.com/search?q="
				+ "flashmob" + "&type=event&limit=" + 5);
		//HTML-Verbindung aufbauen
		HttpURLConnection conn = (HttpURLConnection) overview_url.openConnection();
		conn.addRequestProperty("accept", "text/n3");
		InputStream is = conn.getInputStream();
		//Encoding festlegen
		String encoding = conn.getContentEncoding();
		if (encoding == null) {
			encoding = "ISO-8859-1";
		}
		//Eventliste auslesen
		BufferedReader in = new BufferedReader(new InputStreamReader(is,
				encoding));
		String l;
		StringBuilder sb = new StringBuilder();
		while ((l = in.readLine()) != null) {
			sb.append(l);
			sb.append('\n');
		}
		in.close();
		String str = sb.toString();
//		System.out.println(str);
	}
}
